<template>
  <!-- 为 ECharts 准备一个定义了宽高的 DOM -->
  <div>
    <div ref="main" id="main">
    </div>
  </div>
</template>

<script lang="ts">
import {Vue, Component, Prop, Watch} from 'vue-property-decorator';
import * as echarts from 'echarts';

@Component
export default class Chart extends Vue {
  @Prop({required: true}) chartOption;
  myChart!: echarts.ECharts;



  @Watch('chartOption',{deep:true})
  watchChartOption(value){
    this.myChart.setOption(value);
  }

  created(){
    let myChart = undefined;
  }

  mounted() {
    const {chartOption} = this;

    this.myChart = echarts.init(this.$refs.main as HTMLElement);

    // 使用刚指定的配置项和数据显示图表。
    this.myChart.setOption(this.chartOption);
  }
}
</script>

<style lang="scss" scoped>
#main {
  height: 20vh;
  width: 100%;
}
</style>